package com.budwk.app.sqfwV2.enums;

import com.budwk.app.sqfw.constants.CommonConstants;
import com.budwk.app.sqfw.constants.TemplateIdsConstants;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
public enum LandscapePatrolEnum {
    A(1,"巡林","sqfwV2/landscapePatrol/xl.docx","林长制巡查记录表","sqfwV2/landscapePatrol/templet/林长制巡查记录表.docx", "pdf", "/preview/lh/xlp01.png"),
    B(2,"汛期、地质灾害","sqfwV2/landscapePatrol/dzzh.docx","汛期、地质灾害防治巡查记录表","sqfwV2/landscapePatrol/templet/汛期、地质灾害防治巡查记录表.docx",
            "pdf", "/preview/lh/xqp01.png"),

    C(3,"巡河","sqfwV2/landscapePatrol/xh.docx","河长巡查记录表","sqfwV2/landscapePatrol/templet/河长巡查记录表.docx", "pdf", "/preview/lh/xhp01.png"),
    D(4,"巡林","sqfwV2/landscapePatrol/xl.xlsx","林长巡林巡查情况统计台账表","sqfwV2/landscapePatrol/templet/林长巡林巡查情况统计台账表.xlsx", "excel", "/preview/lh/xle02.png"),

    E(5,"汛期、地质灾害","sqfwV2/landscapePatrol/dzzh.xlsx","地质灾害防治巡查情况统计台账表","sqfwV2/landscapePatrol/templet/地质灾害防治巡查情况统计台账表.xlsx",
            "excel", "/preview/lh/xqe02.png"),

    F(6,"巡河","sqfwV2/landscapePatrol/xh.xlsx","河长巡查记录","sqfwV2/landscapePatrol/templet/河长巡查记录.xlsx", "excel", "/preview/lh/xhe02.png"),
    ;
    private  int code;
    private  String name;
    private  String templat;
    private  String fileName;
    private  String blankTemplate;
    private  String type;
    private  String previewImage;

    public static String getTemplateIds(Integer code) {
        if (A.getCode() == code) {
            return TemplateIdsConstants.LINHE_XL_IDS;
        }
        if (B.getCode() == code) {
            return TemplateIdsConstants.LINHE_DZZH_IDS;
        }
        if (C.getCode() == code) {
            return TemplateIdsConstants.LINHE_XH_IDS;
        }
        return CommonConstants.DOWNIDS_TEMPLATE_IDS;
    }

    public static String getFileName(String name){
        String filename = Arrays.asList(LandscapePatrolEnum.values())
                .stream()
                .filter(e -> name .equals(e.getName())&&e.getCode()<=3 )
                .collect(Collectors.toList())
                .get(0)
                .getFileName();
        return filename;
    }

    public static String getBlankTemplate(Integer code){
        String blankTemplate = Arrays.asList(LandscapePatrolEnum.values())
                .stream()
                .filter(e -> code .equals(e.getCode()) )
                .collect(Collectors.toList())
                .get(0)
                .getBlankTemplate();
        return blankTemplate;
    }
    public static String getName(Integer code){
        String name = Arrays.asList(LandscapePatrolEnum.values())
                .stream()
                .filter(e -> code .equals(e.getCode()) )
                .collect(Collectors.toList())
                .get(0)
                .getName();
        return name;
    }

    public static String getPdfTemplatName(String name){
        String templat = Arrays.asList(LandscapePatrolEnum.values())
                .stream()
                .filter(e -> name .equals(e.getName()) )
                .collect(Collectors.toList())
                .get(0)
                .getTemplat();
        return templat;
    }

    public static String getPdfTemplat(Integer code){
        String templat = Arrays.asList(LandscapePatrolEnum.values())
                .stream()
                .filter(e ->  code .equals(e.getCode()) )
                .collect(Collectors.toList())
                .get(0)
                .getTemplat();
        return templat;
    }
    public static String getFileName(Integer code){
        String fileName = Arrays.asList(LandscapePatrolEnum.values())
                .stream()
                .filter(e -> code .equals(e.getCode()) )
                .collect(Collectors.toList())
                .get(0)
                .getFileName();
        return fileName;
    }


    public static LandscapePatrolEnum findByCode(Integer code) {
        Optional<LandscapePatrolEnum> first = Arrays.stream(values()).filter(e -> e.getCode() == code).findFirst();
        return first.orElse(null);
    }

}
